# #############################################################################
# catkin_make
# #############################################################################

cmake_minimum_required(VERSION 3.10.2)

if(POLICY CMP0048)
    cmake_policy(SET CMP0048 NEW)
endif(POLICY CMP0048)

project(project_template_studio VERSION 1.0.0)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)

SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O4 -Wall -Wno-sign-compare -Wno-unused -Wno-comment -Wno-deprecated-declarations -g -pthread  -Wno-error=register")

configure_file(
    ${PROJECT_SOURCE_DIR}/config.h.in
    ${PROJECT_SOURCE_DIR}/include/utils/config.h
)

configure_file(
    ${PROJECT_SOURCE_DIR}/version.h.in
    ${PROJECT_SOURCE_DIR}/include/utils/version.h
    @ONLY
)

# qt_build provides the qt cmake glue, roscpp the comms for a default talker
find_package(catkin REQUIRED COMPONENTS roscpp
    std_msgs
    sensor_msgs
    geometry_msgs
    cv_bridge

    # pcl library
    pcl_conversions
    pcl_ros
    rviz
    visualization_msgs
)

find_package(Qt5 REQUIRED Core Widgets Charts)
find_package(Boost REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(OpenCV REQUIRED)

set(QT_LIBRARIES Qt5::Widgets)

include_directories(
    include
    ${catkin_INCLUDE_DIRS})

catkin_package()

# #############################################################################
# Sections
# #############################################################################
file(GLOB QT_FORMS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ui/*.ui)
file(GLOB QT_RESOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} resources/*.qrc)
file(GLOB_RECURSE QT_MOC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS include/*.hpp *.h)

QT5_ADD_RESOURCES(QT_RESOURCES_CPP ${QT_RESOURCES})
QT5_WRAP_UI(QT_FORMS_HPP ${QT_FORMS})
QT5_WRAP_CPP(QT_MOC_HPP ${QT_MOC})

# #############################################################################
# Sources
# #############################################################################
file(GLOB_RECURSE QT_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} FOLLOW_SYMLINKS app/*.cpp src/*/*.cpp)

file(GLOB_RECURSE
    utils_src_files
    ${PROJECT_SOURCE_DIR}/src/utils/*.cc
    ${PROJECT_SOURCE_DIR}/src/param/*.cc
)

add_library(
    pts_utils
    SHARED
    ${utils_src_files}
)
target_link_libraries(
    pts_utils
    ${PCL_LIBRARIES}
    ${YAML_CPP_LIBRARIES}
    ${OpenCV_LIBRARIES}
    ${catkin_LIBRARIES}
)

# #############################################################################
# Binaries
# #############################################################################
add_executable(project_template ${QT_SOURCES} ${QT_RESOURCES_CPP} ${QT_FORMS_HPP} ${QT_MOC_HPP})

target_link_libraries(project_template
    ${QT_LIBRARIES}
    pthread
    ${CMAKE_DL_LIBS}

    pts_utils
)

# 添加可执行文件
install(TARGETS project_template RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})

# 添加头文件
install(DIRECTORY include
    DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
)

# 添加launch文件
install(DIRECTORY launch
    DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
